class HistoryModel {
  key = 'history'
  maxLength = 10
  getHistoryItems(){
    let historyItems = wx.getStorageSync(this.getKey()) || [];
    return historyItems;
  }
  getKey(){
    return this.key;
  }
  addToHistory(item){
    let historyItems = this.getHistoryItems();
    if(!historyItems.includes(item)){
      historyItems.unshift(item)
      if(historyItems.length>=this.maxLength){
        historyItems.pop();
      }
      wx.setStorageSync(this.getKey(), historyItems);
    }
  }
}
export { HistoryModel }